#!/bin/bash

# WORKINGDIR=$(cd `dirname $0`; pwd)
# FILTERSTR=`echo $WORKINGDIR | awk -F '/' '{print $(NF-1)}'`
FILTERSTR="UK"

if [ $# -gt 1 ];then
    
      echo "第一种用法,不带参数,杀死所有的 $FILTERSTR 进程"
      echo "第二种用法,带参数,杀死所有的 $FILTERSTR 进程 中过滤指定名称后的进程"
      echo "第三种用法,没有哦!!!"
      exit 0
    
fi    
    
if [ $# -eq 1 ];then
      echo  -e "\e[1;31m ps -axj | grep -v grep | grep -v redis-server | grep $FILTERSTR |grep -w $1 |awk '{print \$2}' | xargs kill -9 \e[0m"
      # ps -axj | grep -v grep | grep $FILTERSTR  |awk '{print $2}'
      PIDS=`ps -axj | grep -v grep| grep -v redis-server| grep -v $0 | grep $FILTERSTR  | grep -w $1  | awk '{print $2}'`
      echo "过滤到的pid列表 :[$PIDS]"
      NUM=`echo $PIDS | cut -d ' ' -f 1`
      if [ -z $NUM ];then
	  echo "没有过滤到$FILTERSTR 进程"
      else
          echo $PIDS  | xargs kill -9
	  echo "杀死后的$FILTERSTR 进程"
	  ps -axj | grep -v grep| grep -v $0 | grep $FILTERSTR  |grep -w $1 
      fi
else
      echo  -e "\e[1;31m ps -axj | grep -v grep | grep -v redis-server | grep $FILTERSTR |awk '{print \$2}' | xargs kill -9 \e[0m"
      # ps -axj | grep -v grep | grep $FILTERSTR  |awk '{print $2}'
      PIDS=`ps -axj | grep -v grep| grep -v redis-server| grep -v $0 | grep $FILTERSTR  |awk '{print $2}'`
      echo "过滤到的pid列表 :[$PIDS]"
      NUM=`echo $PIDS | cut -d ' ' -f 1`
      if [ -z $NUM ];then
	  echo "没有过滤到$FILTERSTR 进程"
      else
          echo $PIDS  | xargs kill -9
	  echo "杀死后的$FILTERSTR 进程"
	  ps -axj | grep -v grep| grep -v $0 | grep $FILTERSTR 
      fi

fi

 
